package com.example.config.filter;

import com.example.config.RedisCacheConfig;
import com.example.utils.IpUtil;
import org.nutz.dao.Dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by alading-qs on 2016/12/27.
 */

@WebFilter(filterName = "restAPIFilter", urlPatterns = "/*")
public class RestAPIFilter implements Filter {

    private static Logger logger = LoggerFactory.getLogger(RestAPIFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.info("restAPIFilter init");
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        String ip = IpUtil.getIpAddress(request);
        logger.info("restAPIFilter doFilter");
        filterChain.doFilter(req, res);
    }

    @Override
    public void destroy() {
        logger.info("restAPIFilter destroy");
    }
}
